using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RoleSelect : MonoBehaviour
{
    public Transform role;
    public List<Transform> heads;
    public List<Transform> bodys;

    public int headID;
    public int bodyID;
    public Transform weapon;
    public List<Transform> weapons;
    public int weaponID;

    void Awake()
    { 
        if (role == null) role = transform;
        // 遍历所有子节点
        foreach (Transform child in role)
        {
            if (child.name.StartsWith("Head")) heads.Add(child);
            if (child.name.StartsWith("Body")) bodys.Add(child);
        }
        if (weapon){
            foreach (Transform child in weapon){
                weapons.Add(child);
            }
        }
    }
    public void init()
    {
        headID = PlayerPrefs.GetInt("headID");
        setHead(headID);
        bodyID = PlayerPrefs.GetInt("bodyID");
        setBody(bodyID);
    }
    /// <summary>设置头部ID</summary>
    public void setHead(int id)
    {
        headID = id -1;
        for (int i = 0; i < heads.Count; i++) heads[i].gameObject.SetActive(i == headID);
    }

    /// <summary>设置身体ID</summary>
    public void setBody(int id)
    {
        bodyID = id;
        for (int i = 0; i < bodys.Count; i++) bodys[i].gameObject.SetActive(i == bodyID);
    }
    /// <summary>设置武器</summary>
    public void setWeapon(int id)
    {
        weaponID = id;
        for (int i = 0; i < weapons.Count; i++) weapons[i].gameObject.SetActive(i == weaponID);
    }
}
